<%@ page import="com.yinhai.core.common.api.config.impl.SysConfig"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<jsp:directive.page import="java.util.Date" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<%@ taglib prefix="ta" tagdir="/WEB-INF/tags/tatags"%>

<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%">
<head>
<title>电子邮件配置</title>
</head>
<%@ include file="/ta/inc.jsp"%>
<body >
	<ta:pageloading />
		<ta:form id="form1" >
			<ta:panel id="pnl_frm" key="基本信息" >
				<ta:box cols="2" >
					<ta:text id="appKey" key="appKey" readOnly="true" required="true" textHelp="app应用标识" columnWidth="0.8"/>
					<ta:box columnWidth="0.2" cssStyle="margin-left:20px" >
						<ta:checkboxgroup  >
							<ta:checkbox id="defaultApp" value="da" key="默认APP" />
						</ta:checkboxgroup>
					</ta:box>
				</ta:box>
				<ta:text id="masterSecret" key="masterSecret" type="password" textHelp="与appKey结合验证app应用" onChange="Base.showObj('regIdForTest')" required="true"/>
				<ta:text id="testRegistrationId" key="测试RegistrationId" type="text" labelWidth="140" textHelp="app应用分配给手机终端的RegistrationID,如果该手机终端收到测试信息，说明配置有效" required="true"/>
			</ta:panel>
		</ta:form>
		<ta:box cols="3" fit="true" >
			<ta:panel id="centerLeft" key="未分配接入系统" fit="true" columnWidth="0.43">
				<ta:datagrid id="unDistrbutedSystem" fit="true"  selectType="checkbox" forceFitColumns="true" >
					<ta:datagridItem id="id" hiddenColumn="true" ></ta:datagridItem>
					<ta:datagridItem id="systemid" key="系统ID"></ta:datagridItem>
					<ta:datagridItem id="systemname" key="系统名称" ></ta:datagridItem>
				</ta:datagrid>
			</ta:panel>
			<ta:box  columnWidth="0.14" cssStyle="margin-left:10px;margin-top:80px">
				<div style="width:100%;position: relative;" id="centerdiv">
					<ta:button key="增加" cssStyle="display:block;margin:0 auto" icon="xui-icon-next" isShowIcon="true" onClick="batchAddSystem()"/>
					<ta:button key="移除" cssStyle="display:block;margin:0 auto;margin-top:10px;" icon="xui-icon-back" isShowIcon="true" onClick="batchDeleteSystem()"/>
					<ta:button id="btn_save" key="保存" cssStyle="display:block;margin:0 auto;margin-top:30px;" isok="true" isShowIcon="true" onClick="save()"/>
					<ta:button id="btn_close" key="关闭" cssStyle="display:block;margin:0 auto;margin-top:10px;" isShowIcon="true" onClick="parent.Base.closeWindow('editconfigapp')"/>
				</div>
			</ta:box>
			<ta:panel id="centerRight" key="分配到当前应用的接入系统" fit="true" cssStyle="margin-left:10px;"  columnWidth="0.43">
				<ta:datagrid id="distrbutedSystem" fit="true" forceFitColumns="true" selectType="checkbox">
					<ta:datagridItem id="id" hiddenColumn="true" ></ta:datagridItem>
					<ta:datagridItem id="systemid" key="系统ID"></ta:datagridItem>
					<ta:datagridItem id="systemname" key="系统名称" ></ta:datagridItem>
				</ta:datagrid>
			</ta:panel>
			<ta:box cssStyle="display:none">
				<ta:panel id="tmp"  key="分配到当前应用的接入系统" fit="true"  cssStyle="margin-left:10px;">
					<ta:datagrid id="tmpgrid" fit="true" forceFitColumns="true" selectType="checkbox">
						<ta:datagridItem id="id" hiddenColumn="true" ></ta:datagridItem>
						<ta:datagridItem id="systemid" key="系统ID"></ta:datagridItem>
						<ta:datagridItem id="systemname" key="系统名称" ></ta:datagridItem>
					</ta:datagrid>
				</ta:panel>
			</ta:box>
		</ta:box>
</body>
</html>
<script type="text/javascript">
	$(document).ready(function() {
		$("body").taLayout();
	});
	
	/*保存数据*/
	function save(){
		var valid = Base.validateForm("form1");
		if(valid){
			Base.setDisabled("btn_save");
			Base.checkedAllData("distrbutedSystem");
			Base.submit('form1','AppConfigController!validateAppConfig.do',null,null,null,function(){
				Base.confirm("请确认拥有testRegistrationId的手机已收到测试信息。选择【是】将保存配置，选择【否】将返回修改!",function(yes){
					if(yes){
						Base.submit('form1,distrbutedSystem','AppConfigController!updateAppConfig.do',null,null,null,function(){
							parent.Base.submit("","AppConfigController!queryAllAppConfigByPage.do");
						});
					}
					Base.setEnable("btn_save");
				},{"title":"提示","buttonOk":"是","buttonCancel":"否"});
			},function(data){
				Base.alert("aa");
				Base.setEnable("btn_save");
			});
		}
	}
	
	//增加接入系统 
	function batchAddSystem(){
		var sysSelect = Base.getGridSelectedRows("unDistrbutedSystem");
		var sysAll = Base.getGridData("unDistrbutedSystem");
		var otherAll = Base.getGridData("distrbutedSystem");
		if(sysSelect && sysSelect.length > 0 ){
			var s = Ta.util.obj2string(sysSelect);
			var all = Ta.util.obj2string(sysAll);
			var otherAll = Ta.util.obj2string(otherAll);
			Base.submit('','AppConfigController!batchAddSystem.do',{"dto['selected']":s,"dto['all']":all,"dto['otherAll']":otherAll},null,null);
		}else{
			Base.alert("请勾选要使用此APP的接入系统!","warn");
		}
	}
	
	/* 批量移除接入系统 */
	function batchDeleteSystem(){
		var sysSelect = Base.getGridSelectedRows("distrbutedSystem");
		var sysAll = Base.getGridData("distrbutedSystem");
		var otherAll = Base.getGridData("unDistrbutedSystem");
		if(sysSelect && sysSelect.length > 0 ){
			var s = Ta.util.obj2string(sysSelect);
			var all = Ta.util.obj2string(sysAll);
			var otherAll = Ta.util.obj2string(otherAll);
			Base.submit('','AppConfigController!batchDeleteSystem.do',{"dto['selected']":s,"dto['all']":all,"dto['otherAll']":otherAll},null,null);
		}else{
			Base.alert("请勾选要移出此APP的接入系统!","warn");
		}
	} 
	
	/* 验证APP配置是否真实可用 */
	function validate(){
		Base.submit("appKey,masterSecret,testRegistrationId","AppConfigController!validateAppConfig.do");
	}
</script>
<%@ include file="/ta/incfooter.jsp"%>